package com.geostar.constructionland.analyse.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.geostar.constructionland.common.entity.analyse.FxrzStatistics;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author chengan
 * @descri 分析日志统计界面mapper
 */
public interface FxrzStasticMapper {
//    For Oracle
    @Select("select * from (select ywid,count(case when fxjg='true' then 1 else null end) as success," +
            "count(1) as total，(select max(a.fxsj) from jsyd_fxrz a where a.ywid = t.ywid and a.fxlx='TZHDLFX') as tzhdlfxtime from " +
            "(select ywid,fxjg from jsyd_fxrz where ywid is not null and fxjg is not null) t group by ywid) t ${ew.customSqlSegment}")


//    @Select("select * from (select ywid,count(case when fxjg='true' then 1 else null end) as success," +
//            "count(1) as total，(select max(a.fxsj) from jsyd_fxrz a where a.ywid = t.ywid and a.fxlx='TZHDLFX') as tzhdlfxtime from " +
//            "(select ywid,fxjg from jsyd_fxrz where ywid is not null and fxjg is not null) t group by ywid) t ${ew.customSqlSegment}")
    IPage<FxrzStatistics> getFxrzStastics(IPage<FxrzStatistics> page, @Param(Constants.WRAPPER)Wrapper<FxrzStatistics> fxrzStatisticsWrapper);

// Query Sql For ORACLE!!!
    @Select("SELECT ywid" +
            "  FROM (SELECT TMP.*, ROWNUM ROW_ID" +
            "          FROM (select ywid from(select t.ywid" +
            "                  from jsyd_fxrz t" +
            "                 where t.ywid is not null" +
            "                   and t.fxsj is not null" +
            "                 order by fxsj desc)t" +
            "                 group by t.ywid" +
            "                 ) TMP)" +
            " WHERE row_id > #{initRow}" +
            "   and row_id <= #{endRow}")
    // Query Sql For MySQL!!!
//    @Select("SELECT TMP.ywid FROM (\n" +
//            "SELECT ywid FROM (\n" +
//            "SELECT t.ywid FROM jsyd_fxrz t WHERE t.ywid IS NOT NULL AND t.fxsj IS NOT NULL ORDER BY fxsj DESC) t GROUP BY t.ywid) TMP LIMIT #{initRow},#{endRow}")
    List<String> getYwid(@Param("initRow") int initRow,@Param("endRow") int endRow);

    List<FxrzStatistics> getFxrzStatistics(List<String> ywid);

    Integer getFxrzStatisticsCount();

}
